<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ExtensoReal</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ExtensoReal</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/vendor/plugins/brazilian-rails/lib/number_portuguese_rb.html">
                vendor/plugins/brazilian-rails/lib/number_portuguese.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000037">por_extenso_em_reais</a>&nbsp;&nbsp;
      <a href="#M000039">por_extenso_em_reais</a>&nbsp;&nbsp;
      <a href="#M000038">to_extenso_real</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="Extenso.html">Extenso</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000039" class="method-detail">
        <a name="M000039"></a>

        <div class="method-heading">
          <a href="#M000039" class="method-signature">
          <span class="method-name">por_extenso_em_reais</span><span class="method-args">(valor)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Escreve o numero por extenso em reais.
</p>
<p>
Exemplo:
</p>
<pre>
 Extenso.por_extenso_em_reais(1) ==&gt; &quot;um real&quot;
 Extenso.por_extenso_em_reais(100) ==&gt; &quot;cem reais&quot;
 Extenso.por_extenso_em_reais(100.58) ==&gt; &quot;cem reais e cinquenta e oito centavos&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000039-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/brazilian-rails/lib/number_portuguese.rb, line 128</span>
128:   <span class="ruby-keyword kw">def</span> <span class="ruby-constant">ExtensoReal</span>.<span class="ruby-identifier">por_extenso_em_reais</span>(<span class="ruby-identifier">valor</span>)
129:     <span class="ruby-keyword kw">return</span> <span class="ruby-value str">'grátis'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">valor</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
130:     <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">valor</span>
131:     <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Integer</span> 
132:       <span class="ruby-identifier">extenso</span> = <span class="ruby-constant">Extenso</span>.<span class="ruby-identifier">por_extenso</span>(<span class="ruby-identifier">valor</span>)
133:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">extenso</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^(.*)(ão$|ões$)/</span>
134:         <span class="ruby-identifier">complemento</span> = <span class="ruby-value str">'de '</span>
135:       <span class="ruby-keyword kw">else</span>
136:         <span class="ruby-identifier">complemento</span> = <span class="ruby-value str">''</span>
137:       <span class="ruby-keyword kw">end</span>
138:       <span class="ruby-node">%(#{extenso} #{valor &lt;= 1 ? 'real': &quot;#{complemento}reais&quot;})</span>
139:     <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Float</span>
140:       <span class="ruby-identifier">real</span>,<span class="ruby-identifier">cents</span>=(<span class="ruby-value str">&quot;%.2f&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">valor</span>).<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/\./</span>).<span class="ruby-identifier">map</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">to_i</span>}
141:       <span class="ruby-identifier">valor_cents</span>=<span class="ruby-constant">Extenso</span>.<span class="ruby-identifier">por_extenso</span>(<span class="ruby-identifier">cents</span><span class="ruby-operator">%</span><span class="ruby-value">100</span>)
142:        
143:       <span class="ruby-identifier">valor_cents</span><span class="ruby-operator">+=</span> <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">cents</span>.<span class="ruby-identifier">to_i</span><span class="ruby-operator">%</span><span class="ruby-value">100</span>
144:       <span class="ruby-keyword kw">when</span> <span class="ruby-value">0</span><span class="ruby-operator">:</span> <span class="ruby-value str">&quot;&quot;</span>
145:       <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span><span class="ruby-operator">:</span> <span class="ruby-value str">&quot; centavo&quot;</span>
146:       <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span><span class="ruby-operator">..</span><span class="ruby-value">99</span><span class="ruby-operator">:</span> <span class="ruby-value str">&quot; centavos&quot;</span>
147:       <span class="ruby-keyword kw">end</span> 
148:        
149:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">real</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
150:         <span class="ruby-node">&quot;#{ExtensoReal.por_extenso_em_reais(real.to_i)}#{cents &gt; 0 ? ' e ' + valor_cents : ''}&quot;</span>
151:       <span class="ruby-keyword kw">else</span>
152:         <span class="ruby-node">&quot;#{valor_cents}&quot;</span>
153:       <span class="ruby-keyword kw">end</span>
154:     <span class="ruby-keyword kw">else</span>
155:       <span class="ruby-constant">ExtensoReal</span>.<span class="ruby-identifier">por_extenso_em_reais</span>(<span class="ruby-identifier">valor</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[^\d]/</span>,<span class="ruby-value str">'.'</span>).<span class="ruby-identifier">to_f</span>)
156:     <span class="ruby-keyword kw">end</span>
157:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000037" class="method-detail">
        <a name="M000037"></a>

        <div class="method-heading">
          <a href="#M000037" class="method-signature">
          <span class="method-name">por_extenso_em_reais</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Escreve por extenso em reais.
</p>
<p>
Exemplo:
</p>
<pre>
 1.por_extenso_em_reais ==&gt; 'um real'
 (100.58).por_extenso_em_reais ==&gt; 'cem reais e cinquenta e oito centavos'
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000037-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/brazilian-rails/lib/number_portuguese.rb, line 112</span>
112:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">por_extenso_em_reais</span>
113:     <span class="ruby-constant">ExtensoReal</span>.<span class="ruby-identifier">por_extenso_em_reais</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>)
114:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000038" class="method-detail">
        <a name="M000038"></a>

        <div class="method-heading">
          <a href="#M000038" class="method-signature">
          <span class="method-name">to_extenso_real</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
DEPRECATION WARNING: use <a
href="ExtensoReal.html#M000037">por_extenso_em_reais</a>, pois este sera
removido no proximo release.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000038-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/brazilian-rails/lib/number_portuguese.rb, line 117</span>
117:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_extenso_real</span>
118:     <span class="ruby-identifier">warn</span>(<span class="ruby-value str">'DEPRECATION WARNING: use por_extenso_em_reais, pois este sera removido no proximo release.'</span>)
119:     <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">por_extenso_em_reais</span>
120:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>